<?php
$mysqli = new mysqli ( 'localhost', 'root', '', 'dieukhacnonbo' );

if ($mysqli->connect_errno) {
	die ( "Failed to connect to DB: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error );
} else {
	if (! $mysqli->set_charset ( 'utf8' )) {
		echo 'error charset utf8';
	} else {
		$sql = "select * from Danh_muc_sp where FatherId is null ";
		$cats = $mysqli->query ( $sql );
		if ($mysqli->errno) {
			die ( "error" . $mysqli->error );
		}
		
		while ( $row = $cats->fetch_assoc () ) {
			echo "<li> <a href='index.php?CatId=" . $row ['Id'] . "'>" . $row ["Name"] . "</a></li>";
			
			$sql = "select * from Danh_muc_sp where FatherId = " . $row ["Id"];
			$chidren = $mysqli->query ( $sql );
			
			while ( $r = $chidren->fetch_assoc () ) {
				echo "<li> <a href='index.php?CatId=" . $r ['Id'] . "'><ul><li>" . $r ["Name"] . "</li></ul></a></li>";
			}
		}
	}
}
?>